package com.atguigu.day09;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class Flink11_SQL_RowTime {
    public static void main(String[] args) {
        //1.获取相关环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        //设置时区
        Configuration configuration = tableEnv.getConfig().getConfiguration();
        configuration.setString("table.local-time-zone", "GMT");


        //TODO 2.在DDL建表语句中指定事件时间
        tableEnv.executeSql("create table sensor(" +
                "id String," +
                "ts bigint," +
                "vc int," +
//                "et as to_timestamp(from_unixtime(ts/1000,'yyyy-MM-dd HH:mm:ss'))," +
                "et as to_timestamp_ltz(ts,3)," +
                "watermark for et as et - interval '5' second" +
                ") with(" +
                "'connector' = 'filesystem'," +
                "'path' = 'input/sensor-sql.txt'," +
                "'format' = 'csv'" +
                ")");

        tableEnv.executeSql("select * from sensor").print();
    }
}
